package org.mm.proxycache;

import org.apache.mina.common.IoBuffer;
import org.mm.proxycache.http.HttpResponse;
import org.mm.proxycache.http.HttpResponseStatus;
import org.mm.proxycache.http.codec.CompleteHttpResponse;

public class HttpResponses
{

    private static String content = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
            + "<html><head>\n"
            + "<title>ERROR: The requested URL could not be retrieved</title>\n"
            + "</head><body>\n"
            + "<h2>The requested URL could not be retrieved</h2>\n"
            + "<p>Unable to determine IP address from host name.</p>\n" + "<hr /></body></html>";

    private static byte emptyBuffer[] = new byte[] {};

    public static HttpResponse getNameErrorResponse()
    {
        CompleteHttpResponse response = new CompleteHttpResponse();

        response.status( HttpResponseStatus.ServiceUnavailable );
        response.contentType( "text/html" );
        response.contentLength( content.length() );
        response.setCurrentDate();
        response.setData( IoBuffer.wrap( content.getBytes() ) );
        return response;
    }

    public static HttpResponse getResourceNotModifiedResponse()
    {
        CompleteHttpResponse response = new CompleteHttpResponse();

        response.status( HttpResponseStatus.NotModified );
        response.contentType( "text/html" );
        response.contentLength( 0 );
        response.setCurrentDate();
        response.setData( IoBuffer.wrap( emptyBuffer ) );
        return response;
    }

    public static HttpResponse getHttpsConnectedResponse()
    {
        CompleteHttpResponse response = new CompleteHttpResponse();

        response.status( HttpResponseStatus.OK );
        response.statusReasonPhrase( "Connection established" );
        response.contentLength( 0 );
        response.setCurrentDate();
        response.setData( IoBuffer.wrap( emptyBuffer ) );
        return response;
    }
}
